package com.javaziliao.design.dprecated.state;

import com.javaziliao.design.utils.RedisCommonProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

// 具体状态类，订单发货
@Component
public class DeprecatedSendOrder extends DeprecatedAbstractOrderState {
    @Autowired
    private RedisCommonProcessor redisCommonProcessor;
    // 订单发货后的下一个状态：待收货
    @Autowired
    private DeprecatedReceiveOrder deprecatedReceiveOrder;

    @Override
    public DeprecatedOrder sendOrder(String orderId, DeprecatedOrderContext context) {
        // 订单发货成功后，将订单状态设置为待收货
        DeprecatedOrder order = (DeprecatedOrder) redisCommonProcessor.get(orderId);
        if (!order.getState().equals(ORDER_WAIT_SEND)){
            throw new UnsupportedOperationException("订单状态应该为待发货，当前状态为："+order.getState());
        }
        order.setState(ORDER_WAIT_RECEIVE);
        redisCommonProcessor.set(orderId,order);
        // context.setCurrentState(this.deprecatedReceiveOrder);
        super.notifyObserver(orderId,ORDER_WAIT_RECEIVE);
        return order;
    }
}
